<template>
  <el-container>
    <el-header>
      <nav>
        <router-link to="/">首页</router-link> |
        <router-link to="/products">商品列表</router-link> |
        <template v-if="userStore.token">
          <router-link to="/cart">购物车</router-link> |
          <router-link to="/orders">我的订单</router-link> |
          <a href="#" @click.prevent="logout">退出</a>
        </template>
        <template v-else>
          <router-link to="/login">登录</router-link> |
          <router-link to="/register">注册</router-link>
        </template>
      </nav>
    </el-header>
    
    <el-main>
      <router-view></router-view>
    </el-main>
  </el-container>
</template>

<script setup>
import { useUserStore } from './stores/user'
import { useRouter } from 'vue-router'

const userStore = useUserStore()
const router = useRouter()

const logout = () => {
  userStore.logout()
  router.push('/login')
}
</script>

<style>
.el-header {
  background-color: #409EFF;
  color: white;
  line-height: 60px;
}

nav {
  text-align: center;
}

nav a {
  color: white;
  text-decoration: none;
  margin: 0 10px;
}

nav a.router-link-active {
  font-weight: bold;
}

.el-main {
  padding: 20px;
}
</style> 